﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ATM
{
    class TransferAccountsState2 : ATMState
    {
        public ATM atm;

        public TransferAccountsState2(ATM atm)
        {
            this.atm = atm;
        }

        public void pressPowerButton()
        {
            return;
        }

        public void pressTakeCashButton()
        {
            return;
        }

        public void pressInsertEnvelopButton()
        {
            return;
        }

        public void pressEnterButton()
        {
            if (this.atm.keypadScreen.Text == "")
            {
                System.Windows.Forms.MessageBox.Show("请输入数字后按Enter键确认!");
                return;
            }

            this.atm.commandString = this.atm.keypadScreen.Text;
            this.atm.commandNumber = Convert.ToInt32(this.atm.commandString);
            this.atm.keypadScreen.Text = "";

            if (this.atm.bankDatabase.isValidAccount(this.atm.commandString))
            {
                this.atm.transferAccounts.targetAccount = this.atm.commandString;
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("不存在此账户，请重新输入!");
                return;
            }

            this.atm.transferAccounts.transferAccount(this.atm.bankDatabase);
            this.atm.receipt.receiptDetails = "账号：" + this.atm.transferAccounts.account + "\r\n";
            this.atm.receipt.receiptDetails += "交易类型：转账" + "\r\n";
            this.atm.receipt.receiptDetails += "转账账户:" + this.atm.transferAccounts.targetAccount + "\r\n";
            this.atm.receipt.receiptDetails += "转账金额:" + this.atm.transferAccounts.amount;

            this.atm.log.addLog(this.atm.receipt.receiptDetails);

            this.atm.screen.Text = "转账成功!";
            this.atm.screen.Text += "\r\n\r\n";
            this.atm.screen.Text += "请选择下一步操作:\r\n";
            this.atm.screen.Text += "1、继续业务\r\n";
            this.atm.screen.Text += "2、打印凭条";

            this.atm.setState(this.atm.transferAccountState3);

            return;
        }
    }
}
